<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        button {
            width: 50px;
            height: 20px;
            margin: 100px auto;
        }
    </style>
</head>
<body style="background-color: black;">
    <button>关灯</button>
    <script>
        var btn = document.querySelector('button')
        var body = document.body
        var flag = 1
        btn.onclick = function() {
            if (flag == 1) {
                body.style.backgroundColor = 'balck'
                flag = 0
            }else {
                body.style.backgroundColor = 'white'
                flag = 1
            }
        }
    </script>
</body>
</html>